/**
 * 主页面的一些路由
 */

const express = require('express')

const Student = require('../models/students')

const router = express.Router()

router.get('/', (req, res) => {
  Student.find((err, students) => {
    if (err) return next(err)
    if (req.session.user) {
      return res.render('index.html', {
        user: req.session.user,
        students: students
      })
    }
    res.redirect('/login')
  })
})

module.exports = router